package com.shiroha.video.controller;

import com.shiroha.common.utils.Result;
import com.shiroha.video.service.ILikeService;
import lombok.AllArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

@RestController
@RequestMapping("/vs/like")
@AllArgsConstructor
public class LikeController {

    private final ILikeService likeService;

    // 点赞作品或评论
    @PostMapping
    public Result<String> addLike(
            @AuthenticationPrincipal Jwt jwt,
            @RequestParam Long workId,
            @RequestParam(required = false) Long commentId
    ) {
        return likeService.addLike(UUID.fromString(jwt.getSubject()), workId, commentId) ?
                Result.success("点赞成功") : Result.error("点赞失败");
    }

    // 取消点赞
    @DeleteMapping
    public Result<String> cancelLike(
            @AuthenticationPrincipal Jwt jwt,
            @RequestParam Long workId,
            @RequestParam(required = false) Long commentId
    ) {
        return likeService.removeLike(UUID.fromString(jwt.getSubject()), workId, commentId) ?
                Result.success("取消点赞成功") : Result.error("取消点赞失败");
    }
}
